import Dialog from '@vant/weapp/dialog/dialog'

Page({
  data: {
    list: [],
    // dialogVisible: false,
  },
  async swipeClose(e) {
    const { position, instance } = e.detail

    // swiper-cell 滑块关闭
    instance.close()

    if (position === 'right') {
      // 显示 Dialog 对话框
      // this.setData({
      //   dialogVisible: true,
      // })

      await Dialog.confirm({
        message: '是否删除已绑定房屋？',
      })
      // 点击了确定
      console.log('[ ok ] >', e)

      await wx.http({
        method: 'DELETE',
        url: '/room/' + e.mark.id,
      })

      wx.utils.toast('删除成功！')

      this.loadList()
    }
  },

  goDetail(e) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + e.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },

  async loadList() {
    const res = await wx.http({
      url: '/room',
    })
    this.setData({
      list: res.data,
    })
  },

  onShow() {
    this.loadList()
  },
})
